package com.ruoyi.project.system.newfunction.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.newfunction.domain.Registration_cost;
import com.ruoyi.project.system.newfunction.service.Registration_costService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/registration_cost")
public class Registration_costController extends BaseController {
    @Autowired
    private Registration_costService registration_costService;

    @RequestMapping("/list")
    @PreAuthorize("@ss.hasAnyPermi('system:registration_cost:list')")
    public TableDataInfo findAllByPage(Registration_cost registration_cost){
        startPage();
        List<Registration_cost> allByPage = registration_costService.findAllByPage(registration_cost);
        return getDataTable(allByPage);
    }

    @RequestMapping("/add")
    @PreAuthorize("@ss.hasAnyPermi('system:registration_cost:add')")
    public AjaxResult saveRegistrationCost(@RequestBody Registration_cost registration_cost){
        System.out.println(registration_cost);
        int i = registration_costService.addRegistrationCost(registration_cost);
        return toAjax(i);
    }

    @RequestMapping("/{regId}")
    @PreAuthorize("@ss.hasAnyPermi('system:registration_cost:list')")
    public AjaxResult findOneById(@PathVariable Integer regId){
        Registration_cost oneById = registration_costService.findOneById(regId);
        return AjaxResult.success(oneById);
    }

    @RequestMapping("/update")
    @PreAuthorize("@ss.hasAnyPermi('system:registration_cost:edit')")
    public AjaxResult updateRegistrationCost(@RequestBody Registration_cost registration_cost){
        int i = registration_costService.updateRegistrationCost(registration_cost);
        return toAjax(i);
    }

    @DeleteMapping("/{regIds}")
    @PreAuthorize("@ss.hasAnyPermi('system:registration_cost:remove')")
    public AjaxResult removeRegistrationCost(@PathVariable Long [] regIds){
        int i = registration_costService.removeRegistrationCost(regIds);
        return toAjax(i);
    }
}
